package mo.offer_special;

import java.util.HashSet;
import java.util.Set;

public class L119 {

    private Set<Integer> set = new HashSet<>();

    public int longestConsecutive(int[] nums) {
        for (int num : nums) {
            set.add(num);
        }
        int max = 0;
        for (int num : nums) {
            if (!set.contains(num-1)) {
                int curNum = num;
                int curMax = 1;
                while (set.contains(curNum+1)) {
                    curMax++;
                    curNum++;
                }
                max = Math.max(max, curMax);
            }
        }
        return max;
    }

}
